//
//  WaterSearchTableViewCell.m
//  wsgz
//
//  Created by huck on 2017/5/6.
//  Copyright © 2017年 BoingPay. All rights reserved.
//

#import "WaterSearchTableViewCell.h"
#import "HomeManager.h"
#import "AppUtils.h"
#import "WaterDetailViewController.h"
#import "RecordDetailViewController.h"
#import "SuperviseDetailViewController.h"

@interface WaterSearchTableViewCell ()

@property (nonatomic, copy) NSString *waterId;//整改和巡查选项中保存水体id
@property (nonatomic, copy) NSString *taskId;
@property (nonatomic, copy) NSString *waterName;
@property (nonatomic, assign) NSInteger index;
@property (nonatomic, assign) TaskStatusType status;
@end


@implementation WaterSearchTableViewCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self initSubview];
}

-(void)initSubview
{
}

- (void)setInfo:(WaterInfoData *)data index:(NSInteger)index
{
    _index = index;
    _nameLabel.text = data.waterName;
    _taskId = data.taskId;
    _waterId = data.waterId;
    _waterName = data.waterName;
    CGFloat nameLen = [AppUtils labelSizeWithString:data.waterName font:[UIFont systemFontOfSize:14]  maxSize:CGSizeMake(SCREEN_WIDTH, 22)].width;
    _nameLabelW.constant = nameLen;
    _countryLabel.text = data.waterLocation;
    _scoutTimeLabel.hidden = YES;
    
    _notMyLikeBtn.hidden = YES;
    _myLikeBtn.hidden = YES;
    _superviseBtn.hidden = YES;
    _dealBtn.hidden = YES;
    _infoBtn.hidden = YES;
    _actionBtnW.constant = 0; //有值是65
    _status = data.taskStatus;
    switch (_status) {
        case TaskStatusTypeWatch:
            _superviseBtn.hidden = NO;
            _actionBtnW.constant = 60; //有值是60
            break;
        case TaskStatusTypeDeal:
            _dealBtn.hidden = NO;
            _actionBtnW.constant = 60; //有值是60
            break;
        case TaskStatusTypeFinish:
            _infoBtn.hidden = NO;
            _actionBtnW.constant = 60; //有值是60
            _scoutTimeLabel.hidden = NO;
            _scoutTimeLabel.text = data.scoutTime;
            break;
        default:
            break;
    }
    NSString *unit = [WATER_LEVEL5_BAD isEqualToString:data.waterQualityClassName] ? @"类":@"";
    _label1.text =[NSString stringWithFormat:@" %@%@   ",data.waterQualityClassName,unit];
    _label1.backgroundColor = [AppUtils getQualityClass:data.waterQualityClassName];
//    if(data.isDirect){
//        _directIcon.image = [UIImage imageNamed:@"water_derect_icon"];
//        _directLabel.text = @"污水0直排";
//    }else{
//        _directIcon.image = [UIImage imageNamed:@"water_derect_no_icon"];
//        _directLabel.text = @"非污水0直排";
//    }
}


- (IBAction)likeBtnClick:(UIButton *)sender
{
    [Toast makeText:@"55"];

    NSInteger like = sender.tag;
    if(_followBlock){
        _followBlock((like+1)%2,_index);
    }
}

//查看
- (IBAction)infoBtnClick:(UIButton *)sender
{
    RecordDetailViewController *controller = [[RecordDetailViewController alloc] init];
    controller.recordId = _taskId;
    controller.waterName = _waterName;
    [[AppUtils getNavigationController] pushViewController:controller animated:YES];
}

//巡查
- (IBAction)superviseBtnClick:(UIButton *)sender
{
    SuperviseDetailViewController *controller= [[SuperviseDetailViewController alloc] init];
    controller.waterId = _waterId;
    controller.recordId = nil;
    controller.waterName = _waterName;
    [[AppUtils getNavigationController] pushViewController:controller animated:YES];
}

//整改
- (IBAction)dealBtnClick:(UIButton *)sender
{
    SuperviseDetailViewController *controller= [[SuperviseDetailViewController alloc] init];
    controller.waterId = _waterId;
    controller.recordId = _taskId;
    controller.waterName = _waterName;
    [[AppUtils getNavigationController] pushViewController:controller animated:YES];
}

- (IBAction)cellClick:(UIButton *)sender
{
    switch (_status) {
        case TaskStatusTypeNone:
        {
            WaterDetailViewController *controller = [[WaterDetailViewController alloc] init];
            controller.waterId = _taskId;
            controller.waterName = _waterName;
            [[AppUtils getNavigationController] pushViewController:controller animated:YES];
        }
            break;
        case TaskStatusTypeWatch:
            [self superviseBtnClick:sender];
            break;
        case TaskStatusTypeDeal:
            [self dealBtnClick:sender];

            break;
        case TaskStatusTypeFinish:
            [self infoBtnClick:sender];
            break;
        default:
            break;
    }
}

@end
